package com.maomao.admin.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.maomao.admin.domain.core.vo.TableDataInfo;
import com.maomao.admin.domain.system.entry.SysOpLog;
import com.maomao.admin.model.annotation.Log;
import com.maomao.admin.model.enums.BusinessType;
import com.maomao.admin.service.system.ISysOpLogService;
import com.maomao.admin.web.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.maomao.admin.common.core.domain.AjaxResult;


/**
 * 操作日志记录
 *
 * @author mao.kaiyin
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOpLogController {

    @Autowired
    private ISysOpLogService operLogService;

    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public TableDataInfo<SysOpLog> list(SysOpLog operLog) {
        TableDataInfo<SysOpLog> list = operLogService.selectOpLogPage(operLog);
        return list;
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOpLog operLog) {
        List<SysOpLog> list = operLogService.selectOpLogList(operLog);
        ExcelUtil<SysOpLog> util = new ExcelUtil<SysOpLog>(SysOpLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/{operIds}")
    public AjaxResult remove(@PathVariable Long[] operIds) {
        operLogService.deleteOpLogByIds(operIds);
        return AjaxResult.success();
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/clean")
    public AjaxResult clean() {
        operLogService.cleanOpLog();
        return AjaxResult.success();
    }
}
